# -*- coding: utf-8 -*-
"""
	@author:sirius
	@time:2017.10.19
"""
from texttable import Texttable
from common.util import get_event_list, get_app_list

# 展示app预测列表、计算预测精准度
def show_result(APP_SYS_PATH, neighbors, list_recommend_app_id, items_app, date_dict):
    # 获取所有应用的列表,所有应用id到应用名字的键值对
    dict_app_id2info = get_app_list(APP_SYS_PATH)

    print("日期：" + date_dict['date'])
    print("星期：" + date_dict['week'])
    print("月份：" + date_dict['month'])
    print("时间：" + date_dict['period'])

    neighbors_id = [i[1] for i in neighbors]
    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype(['t', 't', 't'])
    table.set_cols_align(["l", "l", "l"])
    rows = [[u"APP NAME", u"Event ID", u"from userid"]]
    # 打印推荐列表的前20项数据，listRecommendAppId里边存储的仅仅是id
    for app_id in list_recommend_app_id[:5]:
        from_user = []
        for user_id in items_app[app_id[1]]:
            if user_id in neighbors_id:
                from_user.append(user_id)
        # dict_app_id2info[app_id][0]表示应用ID dict_app_id2info[app_id][1]类别ID
        rows.append([app_id[1], dict_app_id2info[app_id[1]], from_user])
    table.add_rows(rows)
    print(table.draw())


# 展示app预测列表、计算预测精准度
def show_result_by_apps(APP_SYS_PATH, list_recommend_app_id, date_dict):
    # 获取所有应用的列表,所有应用id到应用名字的键值对
    dict_app_id2info = get_app_list(APP_SYS_PATH)

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype(['t', 't'])
    table.set_cols_align(['l', 'l'])
    rows = [[u"APP NAME", u"Event ID"]]
    # 打印推荐列表的前20项数据，listRecommendAppId里边存储的仅仅是id
    for app_id in list_recommend_app_id:
        rows.append([app_id[0], dict_app_id2info[app_id[0]]])
    table.add_rows(rows)
    print(table.draw())

    return 75.01928493785729324, 100
